package com.gxa.service.impl;

import com.gxa.common.R;
import com.gxa.dao.SysUserDao;
import com.gxa.dao.impl.SysUserDaoImpl;
import com.gxa.entity.SysUser;
import com.gxa.service.SysUserService;
import com.gxa.utils.MD5Utils;

import java.sql.SQLException;

/**
 * Service层：处理业务逻辑：日志、安全、事务、其他.....
 */
public class SysUserServiceImpl implements SysUserService {

    @Override
    public R login(String account, String password) throws SQLException {
        // 将客户端传递的密码加密
        String newPassword = MD5Utils.encrypt(password);
        // 获取Dao实例对象
        SysUserDao sysUserDao = new SysUserDaoImpl();
        // 调用方法
        SysUser sysUser = sysUserDao.querySysUserByAccount(account);
        // 判断账户和密码是否相等
        if(sysUser != null && sysUser.getPassword().equals(newPassword)){// 登录成功
            return R.success("登录成功！",sysUser);
        }
        return R.error("账户或密码有误！");
    }

}
